package com.example.myandroidapp;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity
{
    private static final String TAG = "MainActivity";

    private TextView myTextView;

    private TextView mySecondTextView;

    private Button buttonOne;

    private Button buttonTwo;

    private Button buttonThree;

    private Button buttonFour;
    
    private Button mFlickrButton;
    
    private MenuItem mMenuItem;
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        Person person = new Person("John", 25, "john.png");

        Log.d(TAG, "-----" + person.toString());

        myTextView = (TextView) this.findViewById(R.id.mytextview);

        // mySecondTextView = new TextView(this.getApplicationContext());

        buttonOne = (Button) this.findViewById(R.id.button_one);

        buttonTwo = (Button) this.findViewById(R.id.button_two);

        buttonThree = (Button) this.findViewById(R.id.button_three);
        
        buttonFour = (Button) this.findViewById(R.id.button_four);
        
        mFlickrButton = (Button) this.findViewById(R.id.button_flickr);

        buttonOne.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v)
            {

                Log.d(TAG, "Button One was clicked");

                myTextView.setText("The button was clicked");

            }
        });

        buttonTwo.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v)
            {

                Log.d(TAG, "Button Two was clicked");
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                intent.setFlags(0);
                startActivity(intent);

            }
        });
        
        buttonFour.setOnClickListener(new View.OnClickListener()
        {
            
            public void onClick(View v)
            {
                Intent intent = new Intent(MainActivity.this, FourthActivity.class);
                
                Bundle bundle = new Bundle();
                bundle.putString("activityname", "FourthActivity");
                
                intent.putExtras(bundle);
             
                startActivity(intent);
                
            }
        });
        
        mFlickrButton.setOnClickListener(new View.OnClickListener()
        {
            
            public void onClick(View v)
            {
                Intent intent = new Intent(MainActivity.this, FlickrPhotoViewerActivity.class);
                Bundle bundle = new Bundle();
                
                bundle.putString("mykey", "myvalue");
                
                intent.putExtras(bundle);
                startActivity(intent);
                
            }
        });
        
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Do you want to proceed to ThirdActivity?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int id)
            {
//                MainActivity.this.finish();
                Intent intent = new Intent(MainActivity.this, ThirdActivity.class);
                int requestCode = 1;
                startActivityForResult(intent, requestCode);
            }
        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int id)
            {
                dialog.cancel();
            }
        });
        final AlertDialog alert = builder.create();

        buttonThree.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v)
            {
                // Intent intent = new Intent(MainActivity.this,
                // ThirdActivity.class);
                // startActivity(intent);

                Toast t = Toast.makeText(getApplicationContext(), "This is a notification", Toast.LENGTH_LONG);

                t.show();
                
                alert.show();

            }
        });
        /*
        mMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener()
        {
            
            public boolean onMenuItemClick(MenuItem item)
            {
                Log.d(TAG, "Here I should handle the click on menu item");
                return true;
            }
        });
        */
    }

    @Override
    public void onPause()
    {
        super.onPause();
        // do something here when app is in background
        Log.d(TAG, "----the Activity returned to the foreground");
    }

    @Override
    public void onResume()
    {
        super.onResume();
        // do something here
        Log.d(TAG, "----the Activity was resumed");
    }

    @Override
    public void onDestroy()
    {
        super.onDestroy();
        Log.d(TAG, "The app is not visible to the user");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    
}
